<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8" />
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>登录 - 空明物联网服务平台</title>
  <link rel="stylesheet" href="/static/css/bootstrap.min.css" />
  <link rel="stylesheet" href="/static/css/main.css?version=1.0.0" />
</head>

<body>
  <div class="wrapper" id="page_index">
    <h1><span class="title">空明物联网服务平台</span></h1>
    <div class="sidebar">
      <ul id="menu" class="menu">
        <li class="selected"><a href="login.html">登录</a></li>
        <li><a href="reg.html">注册</a></li>
      </ul>
    </div>
  </div>
  <div class="main-content">
    <div class="container-fluid">
      <br />
      <h2>用户登录</h2>
      <br />
      <p>如果您忘记了密码，可以点击这里 <a href="pwd.html">找回密码</a></p>
      <p>如果您还没有注册账号，请先点击这里 <a href="reg.html">注册</a></p>
      <p id="info" style="color: #FF0000;"></p>
      <br />
      <p>
        邮箱 ：
        <input type="text" id="email" name="email" required />
      </p>
      <p>
        密码 ：
        <input type="password" id="password" name="password" required />
      </p>
      <p>
        验证码：
        <input type="text" id="validate" name="validate" required /><img src="" id="ruaptcha" height="29px"
          alt="点击刷新验证码" />
      </p>
      <br />

      <div id="captcha">
        <div class="loading">
          <div class="loading-dot"></div>
          <div class="loading-dot"></div>
          <div class="loading-dot"></div>
          <div class="loading-dot"></div>
        </div>
      </div>

      <br />
      <button id="login" class="btn btn-primary btn-sm" type="submit">
        登录
      </button>
      <div class="footer">
        <span>© 2020 空明物联网 <a href="http://www.beian.miit.gov.cn/" target="_blank">鄂ICP备15000810号-1</a></span>
      </div>
    </div>

  </div>
  <script src="/static/js/jquery-2.1.4.min.js"></script>
  <script src="/static/js/gt.js"></script>
  <script src="/static/js/base.js?version=1.0.0"></script>
  <script>
    var t; // 待提交验证码标识

    // 刷新验证码图片
    function flushRuaptcha() {
      var timestamp = (new Date()).valueOf();
      t = timestamp
      $("#ruaptcha").attr("src", getServiceURL("getruaptcha") + "?t=" + timestamp)
    }

    $(document).ready(function () {
      flushRuaptcha();
    });


    $("#ruaptcha").click(function () {
      flushRuaptcha();
    });



    $("#login").click(function () {

      var email = $("#email").val();
      var password = $("#password").val();
      var validate = $("#validate").val();



      if (email == "") {
        return alert("请输入电子邮箱账号！");
      }

      if (password == "") {
        return alert("请输入密码！");
      }

      if (validate == "") {
        return alert("请输入验证码！");
      }

      $.ajax({
        url: getServiceURL("login"),
        data: {
          "email": email,
          "password": password,
          "t": t,
          "validate": validate,
        },
        type: "post",
        async: false,
        success: function (res) {
          if (res.code == 0) {
            setSession(res.data.user);
            setTimeout(function () {
              location.href = "./";
            }, 500);
          } else {
            alert(res.msg);
            flushRuaptcha();
          }
        }
      });
      return false;

    });

    
    // 回车键提交
    $("#validate").keydown(function () {
      if (event.keyCode == "13") {
        $("#login").click();
      }
    });
  </script>
</body>

</html>